#ifndef A_LOOPER_ROSTER_H_
#define A_LOOPER_ROSTER_H_

#include <ALooper.h>
#include <map>
#include "memory"
#include "string"

class ALooperRoster {
public:
    ALooperRoster();

    ALooper::handler_id registerHandler(
            const std::shared_ptr<ALooper> &looper, const std::shared_ptr<AHandler> &handler);

    void unregisterHandler(ALooper::handler_id handlerID);
    void unregisterStaleHandlers();

private:
    struct HandlerInfo {
        std::weak_ptr<ALooper> mLooper;
        std::weak_ptr<AHandler> mHandler;
    };

    std::mutex mLock;
    std::map<ALooper::handler_id, HandlerInfo> mHandlers;
    ALooper::handler_id mNextHandlerID;
};


#endif  // A_LOOPER_ROSTER_H_
